package com.mql.gre.beans;

import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Iterator;

import javax.xml.bind.annotation.XmlRootElement;
 @XmlRootElement
public class Document {
	private String id;
	private HashMap<String, Object> data;

	public Document() {
		data = new HashMap<String, Object>();

	}

	public Document(String id, HashMap<String, Object> data) {
		super();
		this.id = id;
		this.data = data;
	}

	public Document(HashMap<String, Object> data) {
		super();
		this.data = data;
	}

	public HashMap<String, Object> getData() {
		return data;
	}

	public void setData(HashMap<String, Object> data) {
		this.data = data;
	}

	public Object get(String property) {
		return data.get(property);
	}

	public void set(String property, Object value) {
		data.put(property, value);
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String toString() {
		return "Document [data=" + data + "]";
	}

	public String toXML() throws FileNotFoundException {
		StringBuffer sb = new StringBuffer();
		sb.append("<document id=\"" + this.id + "\">");

		for (Iterator iterator = data.keySet().iterator(); iterator.hasNext();) {
			String key = (String) iterator.next();
			sb.append("    <" + key + ">" + data.get(key).toString() + "</"
					+ key + ">");
		}
		sb.append("</document>");

		return sb.toString();

	}

}
